import { queryLinkList } from "@/api/link.api";
import { Link } from "@/types/link";
import { Ref, onMounted, ref } from "vue";

export const useLinkList = (): {
  linkList: Ref<Array<Link>>;
  goToLink: (link: Link) => void;
} => {
  const linkList = ref<Array<Link>>([]);
  const getLinkList = async () => {
    const res = await queryLinkList();
    if (res.code === 200) {
      linkList.value = res.data || [];
    }
  };
  const goToLink = (link: Link) => {
    if (link.address) {
      window.open(link.address);
    }
  };
  onMounted(() => {
    getLinkList();
  });
  return {
    linkList,
    goToLink,
  };
};
